<template>
  <div>
    <h1>Count-{{ tenSumAndOne }}</h1>
    <h1>我在尚硅谷{{ school }}学{{ subject }}</h1>

    <h2>当前求和为{{ sum }}</h2>
    <select v-model.number="n">
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
    </select>
    <button @click="increment(n)">+</button>
    <button @click="decrement(n)">-</button>
    <button @click="incrementOdd(n)">奇数+</button>
    <button @click="incrementWait(n)">等一等+</button>
  </div>
</template>

<script>
import { mapState } from "vuex";
import { mapGetters } from "vuex";
import { mapActions } from "vuex";
import { mapMutations } from "vuex";
export default {
  data: function () {
    return {
      n: 1,
    };
  },
  computed: {
    // 使用api快速生成映射函数
    // sum(){
    //   return $.store.state.sum
    // },

    ...mapState(["sum", "school", "subject"]),
    ...mapGetters(["tenSumAndOne"]),
  },
  mounted() {
    console.log(this);
  },
  methods: {
    // increment() {
    //   // this.$store.dispatch("jia", this.n);
    //   //简单的逻辑直接加
    //   this.$store.commit("JIA", this.n);
    // },
    // decrement() {
    //   this.$store.dispatch("jian", this.n);
    // },
    // incrementOdd() {
    //   this.$store.dispatch("incrementOdd", this.n);
    // },
    // incrementWait() {
    //   this.$store.dispatch("incrementWait", this.n);
    // },
    ...mapActions({
      increment: "jia",
      incrementOdd: "incrementOdd",
      incrementWait: "incrementWait",
    }),
    ...mapMutations({
      decrement: "JIAN",
    }),
  },
};
</script>

<style scoped>
button {
  margin-left: 10px;
}
</style>